import { baseUrl } from '@/env.config.js'
import useStore from '@/stores/userStore.js'

const fileStrTypeMap = {
  video: '1',
  images: '2',
  file: '3',
}
const apiUpLoad = (file) => {
  const { userInfo, token } = useStore()
  const { fileType, tempFilePath, size } = file
  return new Promise((resolve, reject) => {
    uni.uploadFile({
      url: baseUrl + '/light/fileController/uploadFile', //仅为示例，非真实的接口地址
      filePath: tempFilePath,
      name: 'file',
      header: {
				"h-authorization-token": token
			},
      complete: (res) => {
        const { statusCode, data, errMsg } = res
        if (statusCode === 200) {
          const resData = JSON.parse(data)
          if (resData.code === 200) {
            resolve(resData.data)
          } else {
            reject(resData)
          }
        } else {
          reject(errMsg)
        }
      },
    })
  })
}

export { apiUpLoad }
